home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / layout / nsBidiUtils.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  12KB  |  246 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * IBM Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 2000
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Maha Abou El Rous <mahar@eg.ibm.com>
  24.  *   Lina Kemmel <lkemmel@il.ibm.com>
  25.  *   Simon Montagu <smontagu@netscape.com>
  26.  *
  27.  * Alternatively, the contents of this file may be used under the terms of
  28.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  29.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  30.  * in which case the provisions of the GPL or the LGPL are applicable instead
  31.  * of those above. If you wish to allow use of your version of this file only
  32.  * under the terms of either the GPL or the LGPL, and not to allow others to
  33.  * use your version of this file under the terms of the MPL, indicate your
  34.  * decision by deleting the provisions above and replace them with the notice
  35.  * and other provisions required by the GPL or the LGPL. If you do not delete
  36.  * the provisions above, a recipient may use your version of this file under
  37.  * the terms of any one of the MPL, the GPL or the LGPL.
  38.  *
  39.  * ***** END LICENSE BLOCK ***** */
  40.  
  41. #ifndef nsBidiUtils_h__
  42. #define nsBidiUtils_h__
  43.  
  44. #include "nsCOMPtr.h"
  45. #include "nsString.h"
  46.  
  47.   /**
  48.    * Perform Arabic shaping on a Unichar string
  49.    * @param aString is the input string
  50.    * @param aLen is the length of aStrong
  51.    * @param aBuf receives the shaped output
  52.    * @param aBuflen receives the length of aBuf
  53.    * @param aInputLogical indicates that the input is in logical order
  54.    * @param aOutputLogical indicates that the output should be in logical order
  55.    */
  56.   nsresult ArabicShaping(const PRUnichar* aString, PRUint32 aLen,
  57.                          PRUnichar* aBuf, PRUint32* aBufLen,
  58.                          PRBool aInputLogical, PRBool aOutputLogical);
  59.  
  60.   /**
  61.    * Scan an nsString, converting characters in the FExx range (Arabic presentation forms) to the equivalent characters in the 06xx
  62.    * range
  63.    * @param aSrc is the input string
  64.    * @param aDst is the output string
  65.    */
  66.   nsresult Conv_FE_06(const nsString& aSrc, nsString& aDst);
  67.  
  68.   /**
  69.    * Scan an nsString, converting characters in the FExx range (Arabic presentation forms) to the equivalent characters in the 06xx
  70.    * range, and also reverse the string
  71.    * @param aSrc is the input string
  72.    * @param aDst is the output string
  73.    */
  74.   nsresult Conv_FE_06_WithReverse(const nsString& aSrc, nsString& aDst);
  75.  
  76.   /**
  77.    * Scan an nsString, converting characters in the 06xx range to the equivalent characters in the 0Fxx range (Arabic presentation
  78.    * forms), with the option to reverse the string
  79.    * @param aSrc is the input string
  80.    * @param aDst is the output string
  81.    * @param aDir indicates whether the string should be reversed
  82.    *        IBMBIDI_TEXTDIRECTION_LTR: do not reverse the string
  83.    *        IBMBIDI_TEXTDIRECTION_RTL: reverse the string
  84.    */
  85.   nsresult Conv_06_FE_WithReverse(const nsString& aSrc, nsString& aDst, PRUint32 aDir);
  86.  
  87.   /**
  88.    * Scan a Unichar string, converting numbers to Arabic or Hindi forms in place
  89.    * @param aBuffer is the string
  90.    * @param aSize is the size of aBuffer
  91.    * @param aNumFlag specifies the conversion to perform:
  92.    *        IBMBIDI_NUMERAL_NOMINAL:      don't do any conversion
  93.    *        IBMBIDI_NUMERAL_HINDI:        convert to Hindi forms (Unicode 0660-0669)
  94.    *        IBMBIDI_NUMERAL_ARABIC:       convert to Arabic forms (Unicode 0030-0039)
  95.    *        IBMBIDI_NUMERAL_HINDICONTEXT: convert numbers in Arabic text to Hindi, otherwise to Arabic
  96.    */
  97.   nsresult HandleNumbers(PRUnichar* aBuffer, PRUint32 aSize, PRUint32  aNumFlag);
  98.  
  99.   /**
  100.    * Scan an nsString, converting numerals to Arabic or Hindi forms
  101.    * @param aSrc is the input string
  102.    * @param aDst is the output string
  103.    */
  104.   nsresult HandleNumbers(const nsString& aSrc, nsString& aDst);
  105.  
  106. // --------------------------------------------------
  107. // IBMBIDI 
  108. // --------------------------------------------------
  109. //
  110. // These values are shared with Preferences dialog
  111. //  ------------------
  112. //  If Pref values are to be changed
  113. //  in the XUL file of Prefs. the values
  114. //  Must be changed here too..
  115. //  ------------------
  116. //
  117. #define IBMBIDI_TEXTDIRECTION_STR       "bidi.direction"
  118. #define IBMBIDI_TEXTTYPE_STR            "bidi.texttype"
  119. #define IBMBIDI_CONTROLSTEXTMODE_STR    "bidi.controlstextmode"
  120. #define IBMBIDI_NUMERAL_STR             "bidi.numeral"
  121. #define IBMBIDI_SUPPORTMODE_STR         "bidi.support"
  122. #define IBMBIDI_CHARSET_STR             "bidi.characterset"
  123.  
  124. #define IBMBIDI_TEXTDIRECTION       1
  125. #define IBMBIDI_TEXTTYPE            2
  126. #define IBMBIDI_CONTROLSTEXTMODE    3
  127. #define IBMBIDI_NUMERAL             4
  128. #define IBMBIDI_SUPPORTMODE         5
  129. #define IBMBIDI_CHARSET             6
  130.  
  131. //  ------------------
  132. //  Text Direction
  133. //  ------------------
  134. //  bidi.direction
  135. #define IBMBIDI_TEXTDIRECTION_LTR     1 //  1 = directionLTRBidi *
  136. #define IBMBIDI_TEXTDIRECTION_RTL     2 //  2 = directionRTLBidi
  137. //  ------------------
  138. //  Text Type
  139. //  ------------------
  140. //  bidi.texttype
  141. #define IBMBIDI_TEXTTYPE_CHARSET      1 //  1 = charsettexttypeBidi *
  142. #define IBMBIDI_TEXTTYPE_LOGICAL      2 //  2 = logicaltexttypeBidi
  143. #define IBMBIDI_TEXTTYPE_VISUAL       3 //  3 = visualtexttypeBidi
  144. //  ------------------
  145. //  Controls Text Mode
  146. //  ------------------
  147. //  bidi.controlstextmode
  148. #define IBMBIDI_CONTROLSTEXTMODE_LOGICAL   1 //  1 = logicalcontrolstextmodeBidiCmd *
  149. #define IBMBIDI_CONTROLSTEXTMODE_VISUAL    2 //  2 = visualcontrolstextmodeBidi
  150. #define IBMBIDI_CONTROLSTEXTMODE_CONTAINER 3 //  3 = containercontrolstextmodeBidi
  151. //  ------------------
  152. //  Numeral Style
  153. //  ------------------
  154. //  bidi.numeral
  155. #define IBMBIDI_NUMERAL_NOMINAL       0 //  0 = nominalnumeralBidi *
  156. #define IBMBIDI_NUMERAL_REGULAR       1 //  1 = regularcontextnumeralBidi
  157. #define IBMBIDI_NUMERAL_HINDICONTEXT  2 //  2 = hindicontextnumeralBidi
  158. #define IBMBIDI_NUMERAL_ARABIC        3 //  3 = arabicnumeralBidi
  159. #define IBMBIDI_NUMERAL_HINDI         4 //  4 = hindinumeralBidi
  160. //  ------------------
  161. //  Support Mode
  162. //  ------------------
  163. //  bidi.support
  164. #define IBMBIDI_SUPPORTMODE_MOZILLA     1 //  1 = mozillaBidisupport *
  165. #define IBMBIDI_SUPPORTMODE_OSBIDI      2 //  2 = OsBidisupport
  166. #define IBMBIDI_SUPPORTMODE_DISABLE     3 //  3 = disableBidisupport
  167. //  ------------------
  168. //  Charset Mode
  169. //  ------------------
  170. //  bidi.characterset
  171. #define IBMBIDI_CHARSET_BIDI        1 //  1 = doccharactersetBidi *
  172. #define IBMBIDI_CHARSET_DEFAULT     2 //  2 = defaultcharactersetBidi
  173.  
  174. #define IBMBIDI_DEFAULT_BIDI_OPTIONS              \
  175.         ((IBMBIDI_TEXTDIRECTION_LTR<<0)         | \
  176.          (IBMBIDI_TEXTTYPE_CHARSET<<4)          | \
  177.          (IBMBIDI_CONTROLSTEXTMODE_LOGICAL<<8)  | \
  178.          (IBMBIDI_NUMERAL_NOMINAL<<12)          | \
  179.          (IBMBIDI_SUPPORTMODE_MOZILLA<<16)      | \
  180.          (IBMBIDI_CHARSET_BIDI<<20))
  181.  
  182.  
  183. #define GET_BIDI_OPTION_DIRECTION(bo) (((bo)>>0) & 0x0000000F) /* 4 bits for DIRECTION */
  184. #define GET_BIDI_OPTION_TEXTTYPE(bo) (((bo)>>4) & 0x0000000F) /* 4 bits for TEXTTYPE */
  185. #define GET_BIDI_OPTION_CONTROLSTEXTMODE(bo) (((bo)>>8) & 0x0000000F) /* 4 bits for CONTROLTEXTMODE */
  186. #define GET_BIDI_OPTION_NUMERAL(bo) (((bo)>>12) & 0x0000000F) /* 4 bits for NUMERAL */
  187. #define GET_BIDI_OPTION_SUPPORT(bo) (((bo)>>16) & 0x0000000F) /* 4 bits for SUPPORT */
  188. #define GET_BIDI_OPTION_CHARACTERSET(bo) (((bo)>>20) & 0x0000000F) /* 4 bits for CHARACTERSET */
  189.  
  190. #define SET_BIDI_OPTION_DIRECTION(bo, dir) {(bo)=((bo) & 0xFFFFFFF0)|(((dir)& 0x0000000F)<<0);}
  191. #define SET_BIDI_OPTION_TEXTTYPE(bo, tt) {(bo)=((bo) & 0xFFFFFF0F)|(((tt)& 0x0000000F)<<4);}
  192. #define SET_BIDI_OPTION_CONTROLSTEXTMODE(bo, cotm) {(bo)=((bo) & 0xFFFFF0FF)|(((cotm)& 0x0000000F)<<8);}
  193. #define SET_BIDI_OPTION_NUMERAL(bo, num) {(bo)=((bo) & 0xFFFF0FFF)|(((num)& 0x0000000F)<<12);}
  194. #define SET_BIDI_OPTION_SUPPORT(bo, sup) {(bo)=((bo) & 0xFFF0FFFF)|(((sup)& 0x0000000F)<<16);}
  195. #define SET_BIDI_OPTION_CHARACTERSET(bo, cs) {(bo)=((bo) & 0xFF0FFFFF)|(((cs)& 0x0000000F)<<20);}
  196.  
  197. /* Constants related to the position of numerics in the codepage */
  198. #define START_HINDI_DIGITS              0x0660
  199. #define END_HINDI_DIGITS                0x0669
  200. #define START_ARABIC_DIGITS             0x0030
  201. #define END_ARABIC_DIGITS               0x0039
  202. #define START_FARSI_DIGITS              0x06f0
  203. #define END_FARSI_DIGITS                0x06f9
  204. #define IS_HINDI_DIGIT(u)   ( ( (u) >= START_HINDI_DIGITS )  && ( (u) <= END_HINDI_DIGITS ) )
  205. #define IS_ARABIC_DIGIT(u)  ( ( (u) >= START_ARABIC_DIGITS ) && ( (u) <= END_ARABIC_DIGITS ) )
  206. #define IS_FARSI_DIGIT(u)  ( ( (u) >= START_FARSI_DIGITS ) && ( (u) <= END_FARSI_DIGITS ) )
  207. #define IS_ARABIC_SEPARATOR(u) ( ( (u) == 0x066A ) || ( (u) == 0x066B ) || ( (u) == 0x066C ) )
  208.  
  209. #define IS_BIDI_DIACRITIC(u) ( \
  210.   ( (u) >= 0x0591 && (u) <= 0x05A1) || ( (u) >= 0x05A3 && (u) <= 0x05B9) \
  211.     || ( (u) >= 0x05BB && (u) <= 0x05BD) || ( (u) == 0x05BF) || ( (u) == 0x05C1) \
  212.     || ( (u) == 0x05C2) || ( (u) == 0x05C4) \
  213.     || ( (u) >= 0x064B && (u) <= 0x0652) || ( (u) == 0x0670) \
  214.     || ( (u) >= 0x06D7 && (u) <= 0x06E4) || ( (u) == 0x06E7) || ( (u) == 0x06E8) \
  215.     || ( (u) >= 0x06EA && (u) <= 0x06ED) )
  216.  
  217. #define IS_HEBREW_CHAR(c) (((0x0590 <= (c)) && ((c)<= 0x05FF)) || (((c) >= 0xfb1d) && ((c) <= 0xfb4f)))
  218. #define IS_06_CHAR(c) ((0x0600 <= (c)) && ((c)<= 0x06FF))
  219. #define IS_FE_CHAR(c) (((0xfb50 <= (c)) && ((c)<= 0xfbFF)) \
  220.                        || ((0xfe70 <= (c)) && ((c)<= 0xfeFC)))
  221. #define IS_ARABIC_CHAR(c) ((0x0600 <= (c)) && ((c)<= 0x06FF))
  222. #define IS_ARABIC_ALPHABETIC(c) (IS_ARABIC_CHAR(c) && \
  223.                                 !(IS_HINDI_DIGIT(c) || IS_FARSI_DIGIT(c) || IS_ARABIC_SEPARATOR(c)))
  224. #define IS_BIDI_CONTROL_CHAR(c) ((0x202a <= (c)) && ((c)<= 0x202e) \
  225.                                 || ((c) == 0x200e) || ((c) == 0x200f))
  226.  
  227. /**
  228.  * The codepoint ranges in the following macros are based on the blocks
  229.  *  allocated, or planned to be allocated, to right-to-left characters in the
  230.  *  BMP (Basic Multilingual Plane) and SMP (Supplementary Multilingual Plane)
  231.  *  according to
  232.  *  http://unicode.org/Public/UNIDATA/extracted/DerivedBidiClass.txt and
  233.  *  http://www.unicode.org/roadmaps/
  234.  */
  235.  
  236. #define IS_IN_BMP_RTL_BLOCK(c) ((0x590 <= (c)) && ((c) <= 0x8ff))
  237. #define IS_RTL_PRESENTATION_FORM(c) (((0xfb1d <= (c)) && ((c) <= 0xfdff)) || \
  238.                                      ((0xfe70 <= (c)) && ((c) <= 0xfefc)))
  239. #define IS_IN_SMP_RTL_BLOCK(c) ((0x10800 <= (c)) && ((c) <= 0x10fff))
  240. #define UCS2_CHAR_IS_BIDI(c) ((IS_IN_BMP_RTL_BLOCK(c)) || \
  241.                               (IS_RTL_PRESENTATION_FORM(c)))
  242. #define UTF32_CHAR_IS_BIDI(c)  ((IS_IN_BMP_RTL_BLOCK(c)) || \
  243.                                (IS_RTL_PRESENTATION_FORM(c)) || \
  244.                                (IS_IN_SMP_RTL_BLOCK(c)))
  245. #endif  /* nsBidiUtils_h__ */
  246.